package com.hanyi.ssm.contorller;

import com.hanyi.ssm.domain.Account;
import com.hanyi.ssm.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class AccountContorller {

    @Autowired
    AccountService accountService;
    @GetMapping("/account/list")
    public List<Account> list(){
        List<Account> accounts = accountService.selectAll();
        System.out.println("accounts = " + accounts);
        return accounts;
    }

    @GetMapping("/account/{id}")
    public Account selectById(@PathVariable("id") Integer id){
        return accountService.selectById(id);
    }

    @PostMapping("/account")
    public String insert(@RequestBody Account account){
        accountService.insert(account);
        return "200";
    }

    @PutMapping("/account")
    public String update(@RequestBody Account account){
        accountService.update(account);
        return "200";
    }

    @DeleteMapping("/account/{id}")
    public String delete(@PathVariable("id") Integer id){
        accountService.delete(id);
        return "200";
    }
}
